<template>
  <div class="stu_teaUpdatePwd">


    <el-form :model="pwdForm" status-icon :rules="pwd" ref="pwdForm" label-width="100px"
             class="demo-ruleForm">
      <el-row style="margin-top: 20px">
        <el-col :offset="2" :span="9">
          <el-form-item label="原密码：" prop="original_password">
            <el-input type="password" v-model="pwdForm.original_password" clearable autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="新密码：" prop="new_password">
            <el-input type="password" v-model="pwdForm.new_password" clearable autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="确认密码：" prop="confirm_password">
            <el-input type="password" onfocus="this.type='password'" v-model="pwdForm.confirm_password" clearable autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="3" :span="2">
          <el-form-item>
            <el-button type="primary" @click="submitForm2('pwdForm')">保存</el-button>
          </el-form-item>
        </el-col>
        <el-col :offset="1" :span="2">
          <el-form-item>
            <el-button @click="resetForm2('pwdForm')">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  export default {

    data() {


//修改密码
      var checkOriginal_password = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入原密码'));
        } else {
          callback();
        }
      };
      var checkNew_password = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入新密码'));
        }
        callback();
      };
      var checkConfirm_password = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入新密码'));
        } else if (value !== this.pwdForm.new_password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {

        remarks: '',

        pwdForm: {
          original_password: '',
          new_password: '',
          confirm_password: '',
        },
        pwd: {
          original_password: [{validator: checkOriginal_password, trigger: 'blur'}],
          new_password: [{validator: checkNew_password, trigger: 'blur'}],
          confirm_password: [{validator: checkConfirm_password, trigger: 'blur'}],
        },
      };
    },
    computed: {},
    methods: {


      submitForm2(formName) { //保存
        //修改密码
        var self = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$http.post(this.URL.api + `user/updatepasswd/` + this.$cookie.get("userid"), self.qs.stringify(self.pwdForm))
              .then(res => {
                if (res.data.flag) {
                  this.$message({
                    message: '添加成功',
                    type: 'success'
                  });
                } else {
                  this.$message.error("添加失败");
                }

              }).catch(res => {
              this.$message.error("添加失败");
            })

          }
        });
      },
      resetForm2(formName) {
        this.$refs[formName].resetFields();

      }
    },
    mounted: function () {



    }
  }
</script>

<style scoped>

</style>
